export let song_detail = {
  namespaced: true,
  state: {
    song_detail_data: {},
    song_detail_flag: false,
    song_data: {},
    song_data_flag: false,
    songs_detail_data: {},
    songs_detail_flag: false,
  },
  actions: {
    // 正在播放歌曲详情
    getSongDetailData(store, data = {}) {
      let url = "/song/detail?ids=" + data.ids;
      return new Promise((resolve, reject) => {
        axios.get(url).then(({
          data
        }) => {
          store.commit("setSongDetailData", data);
          resolve(data);
        }).catch((error) => {
          if (error.response) {
            // 请求已发出，但服务器响应的状态码不在 2xx 范围内
            reject(error.response.data)
          }
        });
      });
    },
    // 任意歌曲详情
    getSongData(store, data = {}) {
      let url = "/song/detail?ids=" + data.ids;
      return new Promise((resolve, reject) => {
        axios.get(url).then(({
          data
        }) => {
          store.commit("setSongData", data);
          resolve(data);
        }).catch((error) => {
          if (error.response) {
            // 请求已发出，但服务器响应的状态码不在 2xx 范围内
            reject(error.response.data)
          }
        });
      });
    },
    getSongsDetailData(store, data = {}) {
      let url = "/song/detail?ids=" + data.ids;
      return new Promise((resolve, reject) => {
        axios.get(url).then(({
          data
        }) => {
          store.commit("setSongsDetailData", data);
          resolve(data);
        }).catch((error) => {
          if (error.response) {
            // 请求已发出，但服务器响应的状态码不在 2xx 范围内
            reject(error.response.data)
          }
        });
      });
    },
  },
  mutations: {
    setSongDetailData(state, data) {
      if (Object.keys(data).length === 0) {
        state.song_detail_flag = false;
      } else {
        state.song_detail_flag = true;
      }
      state.song_detail_data = data;
    },
    setSongData(state, data) {
      if (Object.keys(data).length === 0) {
        state.song_data_flag = false;
      } else {
        state.song_data_flag = true;
      }
      state.song_data = data;
    },
    setSongsDetailData(state, data) {
      if (Object.keys(data).length === 0) {
        state.songs_detail_flag = false;
      } else {
        state.songs_detail_flag = true;
      }
      state.songs_detail_data = data;
    },
  }
}
